package org.example.rubbish.mapper;



import org.apache.ibatis.annotations.*;
import org.example.rubbish.entity.User;

import java.util.List;

@Mapper
public interface UserMapper {
    @Insert("INSERT INTO user(username, password, salt, phone, email, status, is_blacklist) " +
            "VALUES(#{username}, #{password}, #{salt}, #{phone}, #{email}, #{status}, #{isBlacklist})")
    @Options(useGeneratedKeys = true, keyProperty = "id")
    void insert(User user);

    @Update("UPDATE user SET username=#{username}, phone=#{phone}, email=#{email}, status=#{status}, " +
            "is_blacklist=#{isBlacklist}, update_time=NOW() WHERE id=#{id}")
    void update(User user);

    @Update("UPDATE user SET password=#{password}, salt=#{salt}, update_time=NOW() WHERE id=#{id}")
    void updatePassword(User user);

    @Select("SELECT * FROM user WHERE id=#{id}")
    User selectById(Long id);

    @Select("SELECT * FROM user WHERE username=#{username}")
    User selectByUsername(String username);

    @Select("SELECT * FROM user")
    List<User> selectAll();

    @Select("SELECT * FROM user WHERE is_blacklist=#{isBlacklist}")
    List<User> selectByBlacklist(Boolean isBlacklist);
}

